<html>

<head>
<title>Online compiler</title>
<link rel=stylesheet href="../Resource/docs.css">
<link rel="stylesheet" href="../Resource/codemirror.css">
<script src="../Resource/codemirror.js"></script>
<script src="../Resource/matchbrackets.js"></script>
<link rel="stylesheet" href="../Resource/show-hint.css">
<script src="../Resource/show-hint.js"></script>
<script src="../Resource/clike.js"></script>
<meta http-equiv="Content-Type"  content="text/html;charset=gb2312">  
</head>

<body>
	<form method="POST">
		<textarea style="border-bottom: 0px;" name="code" id="code"></textarea>
	</form>
	
	<script>
      var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
        lineNumbers: true,
        matchBrackets: true,
        mode: "text/x-csrc"
      });
	  
      var mac = CodeMirror.keyMap.default == CodeMirror.keyMap.macDefault;
      CodeMirror.keyMap.default[(mac ? "Cmd" : "Ctrl") + "-Space"] = "autocomplete";
	  
	  function setContent(data)
	  {
		editor.getDoc().setValue(data);
        editor.refresh();
	  }
	  
	  function insertSymbol(data)  
      {  
        insertText(editor,data);
		editor.refresh();
      }  
	  
	  function insertText(obj,str) {
		if (document.selection) {
			var sel = document.selection.createRange();
			sel.text = str;
		} else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
			var startPos = obj.selectionStart,
				endPos = obj.selectionEnd,
				cursorPos = startPos,
				tmpStr = obj.value;
				obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
				cursorPos += str.length;
				obj.selectionStart = obj.selectionEnd = cursorPos;
			} else {
				obj.value += str;
			}
		}

    </script>

</body>

</html>